﻿#region

using Microsoft.Extensions.Hosting;
using Vin.Event;
using Vin.Extension.SqlSugar.EventArgs;
using Vin.Tool.Attributes;

#endregion

namespace Vin.Extension.SqlSugar.Service;

public class SqlSugarInitService : BackgroundService
{
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        if (VinSqlSugarExtension.SqlSugarConfig.SqlSugarOption?.InitTables == true)
        {
            await VinSqlSugarExtension.InitTables();
        }
        
        // 触发初始化
        VinEventManager.Fire<VinSqlSugarInitEventArg>(null, new VinSqlSugarInitEventArg());
    }
}